﻿using Anke.SHManage.BLL;
using DAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Utility;

namespace BLL
{
    public class UserLoginBLL
    {
        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public bool Login(string UserName, string pwd)
        {
            /*
             * 1. 根据用户名密查询用户是否存在
             */
            string pwdMd5 = SecurityHelper.GetMD5(pwd);  //返回MD5加密字符串
            bool result = false;
            UserLoginDAL dal = new UserLoginDAL();
            TY_PersonInfo user = dal.Login(UserName, pwdMd5); //查找用户名 密码
            if (user != null)
            {
                dealSeesion(user); //缓存用户相关信息
                result = true;
            }
            return result;
        }

        private void dealSeesion(TY_PersonInfo user)
        {
            UserOperateContext.Current.Session_UsrInfo = user; //把用户信息存入session中
            UserPopedomBLL upbll = new UserPopedomBLL();  //实例化权限业务
            //UserOperateContext.Current.Session_UsrPopedom = upbll.GetUserPopedom(user.JiaoSeBianMa); //获取用户角色对应权限列表,保存到session中---用户角色权限待补充

            //UserOperateContext.Current.Session_UsrRole = new P_UserRoleBLL().GetListBy(ur => ur.UserID == user.ID).Select(ur => ur.RoleID).ToList(); //把用户角色列表存入 session中：用户单角色---不需要
        }
    }
}
